'use strict';

function getUrlParam(variable) {
  let query = window.location.search.substring(1);
  let vars = query.split('&');
  for (let i = 0; i < vars.length; i++) {
    let pair = vars[i].split('=');
    if (pair[0] == variable) { return pair[1]; }
  }
  return (false);
}

new Vue({
  el: '#login',
  data: {
    email: '',
    password: '',
  },
  methods: {
    doLogin() {
      const body = {
        email: this.email,
        password: this.password,
      };
      //   const that = this;
      $.ajax({
        url: '../login',
        type: 'POST',
        data: body,
        success(data) {
          window.location.href = getUrlParam('redirect');
          $.cookie('user_id', data.id);
          $.cookie('email', data.email);
        },
        error(data) {
          alert('data');
        },
      });
    },
  },
});

